package pt.isel.lercm.projectmanager.spring.commons;

import pt.isel.lercm.projectmanager.auxobjects.Mode;
import pt.isel.lercm.projectmanager.managedController.generic.GenericManagedBean;


public abstract class GenericManagedBeanCrud extends GenericManagedBean{
	
	private Integer id;
	private String mode;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}
	
	public void gravar(){
		if (getMode().equals(Mode.NOVO.mode)){
			gravarNovo();
		}
		else{
			gravarEditar();
		}
	}
	
	public boolean isDisableComponent(){
		if (getMode().equals(Mode.LEITURA.mode) || getMode().equals(Mode.DISABLED.mode)){
			return true;
		}
		
		return false;
	}
	
	public boolean isRenderBotaoGravar(){
		if (!getMode().equals(Mode.LEITURA.mode) && !getMode().equals(Mode.DISABLED.mode)){
			return true;
		}
		
		return false;
	}
	
	public boolean isRenderBotaoEditar(){
		if (getMode().equals(Mode.LEITURA.mode)){
			return true;
		}
		
		return false;
	}
	
	public boolean isRenderBotaoVoltar(){
		if (!getMode().equals(Mode.LEITURA.mode) && !getMode().equals(Mode.DISABLED.mode)){
			return true;
		}
		
		return false;
	}
	
	public boolean isRenderBotaoApagar(){
		if (getMode().equals(Mode.EDICAO.mode)){
			return true;
		}
		
		return false;
	}
	
	public abstract void gravarNovo();
	
	public abstract void gravarEditar();
	
	public abstract void apagar();
	
	public abstract void editar();
	
	public abstract void voltar();
}
